var $$scope;
var $CertusFormAjax;
var $CertusJsonAjax;
var $fileListService;
var yslistGrid;

function addNo(){
    layer.prompt({
        title: '请输入合同编号，并确认！',
        formType: 3
    }, function (text, index) {
        // layer.close(index);
        // layer.msg('合同编号：' + text);
        // location.href='#/addReceive';
        $CertusFormAjax.ajax("receive/canReceive",{contractCode:text},function(res){
            if(res.data){
                if(res.data == "YES"){
                    layer.msg('合同编号号：' + text);
                    text = text.replace("/","@@");

                    location.href='#/addReceive/'+text;
                    layer.closeAll();
                }else{
                    layer.msg("合同无法使用");
                }
            }
        })

    });
}

// 采购验收单管理
var pltlogColumns = [{
    id: 'contractCode',
    title: '报价协议/合同编号',
    type: 'string',
    width: 180,
    columnClass: 'text-center',
}, {
    id: 'checkCode',
    title: '采购验收单编号',
    type: 'string',
    width: 180,
    columnClass: 'text-center',
}, {
    id: 'supplieName',
    title: '供应商',
    type: 'string',
    width: 150,
    columnClass: 'text-center',
}, {
    id: 'acceptanceAddr',
    title: '验收地点',
    type: 'string',
    width: 100,
    columnClass: 'text-center',
}, {
    id: 'acceptDate',
    title: '验收日期',
    type: 'string',
    width: 100,
    columnClass: 'text-center',
}, {
    id: 'descRemark',
    title: '备注说明',
    type: 'string',
    columnClass: 'text-left',
}, {
    id: 'operation',
    title: '操作',
    width: 60,
    type: 'string',
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = '';

        if(record.checkCode){
            record.checkCode = record.checkCode.replace("/","@@");
            content += '<a class="btn btn-xs btn-primary" href="#/selReceive/'+ record.checkCode+'"><i class="icon-eye-open"></i>  查看</a>';
        }
        // content += '  ';
        // content += '<button class="btn btn-xs btn-info" onclick="getast(this);"><i class="icon-ok"></i>  确认询价</button>';
        return content;
    }
}, ];



// 协议购买清单
var purchaselistColumns = [{
    id: 'commodityCateName',
    title: '类目',
    type: 'string',
    width: 75,
    columnClass: 'text-center',
}, {
    id: 'commodityClassName',
    title: '类别',
    type: 'string',
    width: 75,
    columnClass: 'text-center',
}, {
    id: 'name',
    title: '名称',
    type: 'string',
    width: 100,
    columnClass: 'text-center',
}, {
    id: 'descAndSpec',
    title: '品名及规格',
    type: 'string',
    width: 100,
    columnClass: 'text-left',
}, {
    id: 'quantity',
    title: '数量',
    type: 'string',
    width: 100,
    columnClass: 'text-center',
}, {
    id: 'singlePrice',
    title: '单价',
    type: 'string',
    width: 100,
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = '￥' + value + '元';
        return content;
      }
}, {
    id: 'estimatedAmount',
    title: '总价',
    type: 'string',
    width: 100,
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = '￥' + value + '元';
        return content;
      }
}, {
    id: 'remark',
    title: '备注',
    type: 'string',
    columnClass: 'text-left',
}, 
{
    id: 'operation',
    title: '操作',
    width: 100,
    type: 'string',
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = '';
        content += '<button class="btn btn-xs btn-success" onclick="shuplod(\'' + record.biCode + '\',\'' + record.name + '\',\'' + record.descAndSpec + '\')"><i class="icon-edit"></i>  办理验收</button>';
        return content;
    }
}, 
];


// 协议购买清单
var pltogColumns = [{
    id: 'proList',
    title: '类目',
    type: 'string',
    width: 75,
    columnClass: 'text-center',
}, {
    id: 'proType',
    title: '类别',
    type: 'string',
    width: 75,
    columnClass: 'text-center',
}, {
    id: 'proName',
    title: '名称',
    type: 'string',
    width: 100,
    columnClass: 'text-center',
}, {
    id: 'spec',
    title: '品名及规格',
    type: 'string',
    width: 100,
    columnClass: 'text-center',
}, {
    id: 'number',
    title: '数量',
    type: 'string',
    width: 100,
    columnClass: 'text-center',
}, {
    id: 'price',
    title: '单价',
    type: 'string',
    width: 100,
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = '￥' + value + '元';
        return content;
      }
}, {
    id: 'sum',
    title: '总价',
    type: 'string',
    width: 100,
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = '￥' + value + '元';
        return content;
      }
}, {
    id: 'message',
    title: '备注',
    type: 'string',
    columnClass: 'text-left',
}, 
// {
//     id: 'operation',
//     title: '操作',
//     width: 100,
//     type: 'string',
//     columnClass: 'text-center',
//     resolution: function (value, record, column, grid, dataNo, columnNo) {
//         var content = '';
//         content += '<button class="btn btn-xs btn-success" onclick="shuplod()"><i class="icon-edit"></i>  办理验收</button>';
//         return content;
//     }
// }, 
];
var pltogOption = {
    lang: 'zh-cn',
    ajaxLoad: false,
    // loadURL:'url',
    exportFileName: '协议购买清单',
    datas: [{
        proList: '设备',
        proType: '服务器',
        proName: '浪潮服务器',
        spec: '测试数据',
        number: '100',
        price: '￥99.00元',
        sum: '￥999.00元',
        message: '备注测试数据'
    }, {
        proList: '设备',
        proType: '硬件',
        proName: '华硕笔记本',
        spec: '测试数据',
        number: '100',
        price: '￥99.00元',
        sum: '￥999.00元',
        message: '备注测试数据'
    }, {
        proList: '服务',
        proType: '服务',
        proName: '售后服务',
        spec: '测试数据',
        number: '100',
        price: '￥99.00元',
        sum: '￥999.00元',
        message: '备注测试数据'
    }, ],
    columns: pltogColumns,
    gridContainer: 'pltogContainer',
    toolbarContainer: 'pltogToolBarContainer',
    tools: '',
    // check: true,
    // checkWidth: 20,
    // onCheck : function(isChecked, record, grid, dataNo, row, extraCell, e){
    // 	var log = '<p>复选事件触发。是否复选：'+isChecked+'；触发行坐标：'+dataNo+'。</p>';
    // 	appendLog_2_1_11(log);
    // },
    pageSize: 10,
    pageSizeLimit: [10, 15, 20]
};
var pltogGrid = $.fn.dlshouwen.grid.init(pltogOption);
$(function () {
    pltogGrid.load();
});


// 协议验收清单列表
var yslistColumns = [{
    id: 'equipmentName',
    title: '设备名称',
    type: 'string',
    width: 150,
    columnClass: 'text-center',
}, {
    id: 'specification',
    title: '规格(参数)',
    type: 'string',
    // width: 150,
    columnClass: 'text-left',
}, {
    id: 'unit',
    title: '单位',
    type: 'string',
    width: 75,
    columnClass: 'text-center',
}, {
    id: 'receivedNum',
    title: '实收数量',
    type: 'string',
    width: 75,
    columnClass: 'text-center',
}, {
    id: 'purchasePromise',
    title: '采购单位',
    type: 'string',
    width: 75,
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        if(record.purchasePromise == "1"){
            return "合格"
        }
        return "不合格"
    }
}, {
    id: 'acceptPromise',
    title: '验收单位',
    type: 'string',
    width: 75,
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        if(record.purchasePromise == "1"){
            return "合格"
        }
        return "不合格"
    }
},  {
    id: 'remark',
    title: '备注 (固定资产编号)',
    type: 'string',
    width: 200,
    columnClass: 'text-left',
}, 
{
    id: 'operation',
    title: '操作',
    width: 60,
    type: 'string',
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = '';
        content += '<button class="btn btn-xs btn-danger" onclick="del(\''+record.beCode+'\')"><i class="fa fa-trash-o"></i>  删除</button>';
        return content;
    }
}, 
];



// 协议验收清单列表
var ysltlogColumns = [{
    id: 'proList',
    title: '设备名称',
    type: 'string',
    width: 150,
    columnClass: 'text-center',
}, {
    id: 'proType',
    title: '规格(参数)',
    type: 'string',
    // width: 150,
    columnClass: 'text-left',
}, {
    id: 'proName',
    title: '单位',
    type: 'string',
    width: 75,
    columnClass: 'text-center',
}, {
    id: 'spec',
    title: '实收数量',
    type: 'string',
    width: 75,
    columnClass: 'text-center',
}, {
    id: 'number',
    title: '采购单位',
    type: 'string',
    width: 75,
    columnClass: 'text-center',
}, {
    id: 'price',
    title: '验收单位',
    type: 'string',
    width: 75,
    columnClass: 'text-center',
},  {
    id: 'message',
    title: '备注 (固定资产编号)',
    type: 'string',
    width: 200,
    columnClass: 'text-center',
}, 
// {
//     id: 'operation',
//     title: '操作',
//     width: 60,
//     type: 'string',
//     columnClass: 'text-center',
//     resolution: function (value, record, column, grid, dataNo, columnNo) {
//         var content = '';
//         content += '<button class="btn btn-xs btn-danger" onclick="del()"><i class="fa fa-trash-o"></i>  删除</button>';
//         return content;
//     }
// }, 
];
var ysltlogOption = {
    lang: 'zh-cn',
    ajaxLoad: false,
    // loadURL:'url',
    exportFileName: '协议验收清单列表',
    datas: [{
        proList: '思科交换机DS-C9148S-D12P8K9',
        proType: '24个千兆电口,4个1GSFP光纤接口、局域网基础版,支持可堆叠,配套1堆叠模块,0.5m堆叠线缆',
        proName: '台',
        spec: '2',
        number: '合格',
        price: '不合格',
        message: '备注测试数据'
    }, ],
    columns: ysltlogColumns,
    gridContainer: 'ysltlogContainer',
    toolbarContainer: 'ysltlogToolBarContainer',
    tools: '',
    // check: true,
    // checkWidth: 20,
    // onCheck : function(isChecked, record, grid, dataNo, row, extraCell, e){
    // 	var log = '<p>复选事件触发。是否复选：'+isChecked+'；触发行坐标：'+dataNo+'。</p>';
    // 	appendLog_2_1_11(log);
    // },
    pageSize: 10,
    pageSizeLimit: [10, 15, 20]
};
var ysltlogGrid = $.fn.dlshouwen.grid.init(ysltlogOption);
$(function () {
    ysltlogGrid.load();
});
var nowBeCode;
function isBeCodeDifferent(element){
    return element.beCode != nowBeCode;
}

// 点击删除按钮弹窗提示效果
function del(beCode) {
    layer.confirm('确认删除此数据？', {
        btn: ['确认', '取消'] //按钮
    }, function () {

        nowBeCode = beCode;
        yslistGrid.exhibitDatas = yslistGrid.exhibitDatas.filter(isBeCodeDifferent)
        yslistGrid.refresh(false);
        layer.closeAll();
    });
}

// 验收信息展示隐藏效果
function shuplod(a,b,c) {

    $$scope.receiveItem = {
        biCode : a,
        equipmentName : b,
        specification : c,
        beCode : a +  Math.floor(Math.random() * 10)
    }
    $$scope.$apply();

    var status = $(".shuplod").css('display');
    if (status == "none") {
        $(".shuplod").show();
    } else {
        $(".shuplod").hide();
    }
}